<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/20
 * Time: 16:39
 */
namespace app\admin\controller;
use think\Request;
class Check extends Base{
    public function _initialize(){
        //没有登录直接跳转到登录页
        if(is_login() <= 0){
            $this->redirect('login/login');
        }
        if(is_login() == 1){
            return true;
        }
        /*验证过滤 以下页面不做验证*/
        if(request()->action() == 'index' || request()->action() == 'logout' || request()->action() == 'login' || request()->action() ==  'main'){
            return true;
        }
        //验证权限 $auth = new Auth();
        $auth = new Auth();
        if ($auth->check(Request::instance()->module() . '/' . Request::instance()->controller() . '/' . Request::instance()->action(), is_login())) {
            return true;
        } else {
            if(request()->isAjax()){
                exit(json_encode(['code'=>'100020','msg'=>'抱歉，您不具备该权限!']));
            }
$html=<<<html
    <html>
    <head>
        <link rel="stylesheet" type="text/css" href="/static/admin/css/H-ui.min.css" />
        <link rel="stylesheet" type="text/css" href="/static/admin/css/H-ui.admin.css" />
        <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
        <script type="text/javascript" src="/static/admin/js/layer.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            $(function(){
              setInterval("closeWindow()",1500);
                layer.msg('抱歉，您不具备该权限！',{icon: 7,time:1500});
              });
            function closeWindow(){
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
           }
        </script>
    </body>
</html>
html;
                echo $html;exit;
            }
        }
}